//
//  HardwareService.m
//  YRSideViewController
//
//  Created by xiabin on 14/12/31.
//  Copyright (c) 2014年 YueRuo. All rights reserved.
//

#import "HardwareService.h"

static HardwareService *sharedManager;

@implementation HardwareService

+(HardwareService*)sharedInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager=[[HardwareService alloc]init];
        [sharedManager initManager];
    });
    return sharedManager;
}

//初始化
-(void) initManager
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    _userid = (int)[userDefaults integerForKey:@"uid"];
    _username = [userDefaults stringForKey:@"account"];
    _userpw = [userDefaults stringForKey:@"password"];
    _token = [userDefaults stringForKey:@"token"];
    _deviceID = [userDefaults stringForKey:@"deviceID"];
    /*NSString* uid = [SSKeychain passwordForService:@"COM.UM" account:@"intuuid"];
    if (uid != nil) {
        _userid = [uid integerValue];
    }
    _username = [SSKeychain passwordForService:@"COM.UM" account:@"strname"];
    _userpw = [SSKeychain passwordForService:@"COM.UM" account:@"strpw"];*/
}

-(void) setUserid:(int)uid
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setInteger:uid forKey:@"uid"];
    
    /*NSString * intid = [NSString stringWithFormat:@"%d", uid];
    [SSKeychain setPassword: intid
                 forService:@"COM.UM"account:@"intuuid"];*/
    _userid = uid;
}

-(void) setUsername:(NSString *)username
{
    /*[SSKeychain setPassword: username
                 forService:@"COM.UM"account:@"strname"];*/
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setValue:username forKey:@"account"];
    _username = username;
}

-(void) setToken:(NSString *)token
{
    /*[SSKeychain setPassword: username
     forService:@"COM.UM"account:@"strname"];*/
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setValue:token forKey:@"token"];
    _token = token;
}

-(void) setUserpw:(NSString *)userpw
{
    //[SSKeychain setPassword: userpw
    //             forService:@"COM.UM"account:@"strpw"];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setValue:userpw forKey:@"password"];
    _userpw = userpw;
}

-(void) setDeviceID:(NSString *)deviceID
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setValue:deviceID forKey:@"deviceID"];
    _deviceID = deviceID;
}

@end
